package demo01;

import demo01.gun.HelloLexer;
import demo01.gun.HelloParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * Created by Administrator on 2016/6/22.
 */
public class Client {
    public static void main(String[] args) throws Exception{
        byte[] id = "hello world".getBytes() ;
        InputStream is = new ByteArrayInputStream(id) ;

        ANTLRInputStream input = new ANTLRInputStream(is) ; // 实例化antlr的io流
        HelloLexer lexer = new HelloLexer(input) ;          // 初始化词法解析Lexer对象
        CommonTokenStream token = new CommonTokenStream(lexer); // 初始化tonken流
        HelloParser parser = new HelloParser(token) ;       // 初始化语法解析perser对象
        ParseTree tree = parser.s() ;                       // 初始化抽象语法素对象

        DemoVisitor visitor = new DemoVisitor() ;
        visitor.visit(tree) ;
    }
}
